@extends('layouts.default')
@section('content')
@include('modules.thanhmenu') 
<?php
$check = HomeController::checkInTime('dsdetai');
$dsdetai = new CanBoQLDeTaiVaSVDK();
$dsnamhoc = $dsdetai->getnamhoc();
if (isset($_REQUEST['chon'])) {
    if ($_REQUEST['chon'] == 'xoa') {
        $masodt = $_REQUEST['iddt'];
        $dsdetai->destroy($masodt);
    }
}
?>

<div id="mask" style="height: 100%;width:100%;background: #000000;top:0;left:0;z-index: 100; opacity:0.70;filter:alpha(opacity=70);position: fixed;display:none">        
</div>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <?php
    if($check)
    {
    ?>
    <tr>
        <td colspan="4" align="right">
            <input type="button" name="them" value="Thêm Mới Đề Tài" onclick="OpenPop('mask', 'frmThemDeTai')" class="cm_footer exampleDiv" style="color:#fff"/><br/><br/>
        </td>        
    </tr>
    <?php
    }
    else{
        echo "<br/>";
    }
    ?>
    <tr>
        <td colspan="4" align="center">
            <table  width="100%" cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td  align="center" class="cm_footer btop brt" style="color:#fff; font-size: 14px; font-weight: bold">
                        Danh Sách Đề Tài
                    </td>   
                </tr>
                <tr>
                    <td align="center" class="blt bbot brt" style="padding: 5px">
                        <form  method="get" name="frmnk" >
                            Niên khóa:
                            <select name="NienKhoa" id="NienKhoaId">
                                <?php
                                foreach ($dsnamhoc as $dsnamhocs) {
                                    ?>
                                    <option name="<?= $dsnamhocs->nien_khoa ?>" value="<?= $dsnamhocs->nien_khoa ?>" <?php if(Input::get('NienKhoa') == $dsnamhocs->nien_khoa) echo "selected='selected'" ?>>
                                        <?= $dsnamhocs->nien_khoa ?>
                                    </option>
                                    <?php
                                }
                                ?>
                            </select>
                            Học kì:
                            <select name="HocKy" id="HocKyId" >
                                <option  name="HocKy" value="1" <?php if(Input::get('HocKy') == 1) echo "selected='selected'" ?>>1</option>
                                <option name="HocKy" value="2" <?php if(Input::get('HocKy') == 2) echo "selected='selected'" ?>>2</option>
                            </select>
                            <input type="submit" name="buton" value="Xem Đề Tài" title="Xem Danh Sách Đề Tài" class="cm_footer exampleDiv" style="color:#fff"/> 
                        </form>
                    </td>
                </tr>
            </table>
        </td> 
    </tr>
    <?php
    if (Session::has('ketqua')) {
        if (Session::get('ketqua') == true)
            echo "<script>alert('Thêm Đề Tài Mới Thành Công!')</script>";
        else {
            echo "<script>alert('Thêm Đề Tài Mới Thất Bại!')</script>";
        }
    }
    if (isset($_GET['NienKhoa']) && isset($_GET['HocKy'])) {
        $a = $_GET['NienKhoa'];
        $b = $_GET['HocKy'];
        $dsdetai1 = $dsdetai->show(Session::get('infor.id_nd')[0], $a, $b);
        ?>    
        <tr>    
            <td>
                <table  width="100%" border="0" cellspacing="0" cellpadding="0"  >
                    <tr>
                        <td  align="center" colspan="4" class="cm_footer btop brt" style="color:#fff; font-size: 14px; font-weight: bold">
                            Danh Sách Đề Tài - Niên Khóa: <?= $a ?> - Học Kỳ: <?= $b ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="10%" align="center" class="title-danhsachhp blt btop bbot" style="padding: 5px">
                            STT
                        </td>
                        <td width="20%" align="center" class="title-danhsachhp blt btop bbot" style="padding: 5px">
                            Mã Đề Tài 
                        </td>
                        <td width="40%" align="center" class="title-danhsachhp blt btop bbot" style="padding: 5px">  
                            Tên Đề Tài
                        </td>
                        <td width="15%" align="center" class="title-danhsachhp  blt btop brt bbot" style="padding: 5px">  
                            Chỉnh Sửa
                        </td>
                    </tr>
                    <?php
                    $stt = 0;
                    if(count($dsdetai1) != 0)
                    {
                    foreach ($dsdetai1 as $dsdetais) {
                        ?>
                        <tr <?php if ($stt % 2 != 0) echo "style='background:#ccc'" ?>>
                            <td align="center" class="blt bbot" style="padding: 5px">
                                <?= ++$stt ?>
                            </td>
                            <td align="center" class="blt bbot" style="padding: 5px">
                                <?= $dsdetais->ma_so_de_tai ?>
                            </td>
                            <td class="blt bbot" style="padding: 5px">
                                <?= $dsdetais->ten_de_tai ?>
                            </td>
                            <td align='center' class="blt bbot brt" style="padding: 5px"> 
                                <?php
                                if($check)
                               {
                                ?>
                                <img  class="exampleDiv"src="<?= URL ?>public/images/icon_edit.png" title="Sửa"alt="Sửa" onclick="location.href = '?NienKhoa=<?= $a ?>&&HocKy=<?= $b ?>&&chon=sua&&iddt=<?= $dsdetais->ma_so_de_tai ?>'"/>&nbsp;
                                <img class="exampleDiv" src="<?= URL ?>public/images/delete.png" title="Xóa" alt="Xóa" onclick="if (confirm('Xác nhận xóa đề tài này?')) {
                                            location.href = '?NienKhoa=<?= $a ?>&HocKy=<?= $b ?>&chon=xoa&iddt=<?= $dsdetais->ma_so_de_tai ?>'
                                        }"/>
                                <?php
                                }
                                else{
                                    echo "Hết thời gian";
                                }
                                ?>
                            </td>
                        </tr>
                        <?php
                    }
                    }
                    else{
                        ?>
                        <tr> 
                            <td colspan="4" align="center" class="blt bbot brt" style="padding: 5px">
                                <i>Không có đề tài.</i>
                            </td>
                        </tr>
                        <?php
                    }
                    ?>
                </table>
            </td>
        </tr>
        <?php
    }
    if (isset($_REQUEST['chon'])) {
        if ($_REQUEST['chon'] == 'sua') {
            $masodt = $_REQUEST['iddt'];
            $detai = $dsdetai->showdetai($masodt);
            ?>
            <tr>        
                <td colspan="4">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="40%" align="center"  class="cm_footer btop brt" style="color:#fff; font-size: 14px; font-weight: bold">
                                Tên Đề Tài
                            </td>
                            <td width="30%" align="center"  class="cm_footer btop brt" style="color:#fff; font-size: 14px; font-weight: bold">
                                Mô Tả Đề Tài 
                            </td>
                            <td width="30%" align="center"  class="cm_footer btop brt" style="color:#fff; font-size: 14px; font-weight: bold">  
                                Số Lượng SVTH
                            </td>
                        </tr>   
                        <form action="<?= URL ?>cb_suadetai" method="POST" name="frmsua" id="frmsuaID">   
                            <tr>   
                                <td class="blt bbot">
                                    <textarea cols=35 rows=4 name="txttendetai" required ><?= trim($detai[0]->ten_de_tai) ?></textarea>
                                </td>
                                <td class="blt bbot">
                                    <textarea cols=35 rows=4 name="txtmota"><?= trim($detai[0]->mo_ta_de_tai) ?></textarea>
                                </td>
                                <td class="blt bbot brt" align='center'>               
                                    <select name="soluong" >
                                        <option value='1' <?php if ($detai[0]->so_luong_sv_th == 1) echo "selected='selected'" ?>>1</option>
                                        <option value='2' <?php if ($detai[0]->so_luong_sv_th == 2) echo "selected='selected'" ?>>2</option>
                                        <option value='3' <?php if ($detai[0]->so_luong_sv_th == 3) echo "selected='selected'" ?>>3</option>
                                        <option value='4' <?php if ($detai[0]->so_luong_sv_th == 4) echo "selected='selected'" ?>>4</option>
                                        <option value='5' <?php if ($detai[0]->so_luong_sv_th == 5) echo "selected='selected'" ?>>5</option>
                                    </select>
                                </td>
                                <td>
                                    <input name="masodt" type="hidden" value="<?= $masodt ?>"/>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4"  class="blt bbot brt" align='center' style='padding: 5px'>
                                    <input class="cm_footer exampleDiv" style='color:#fff'  type="submit" name="luu" value="Lưu"/>
                                    <input class="cm_footer exampleDiv" style='color:#fff'  type="reset" name="btnlamlai" value="Làm lại"/>
                                </td>
                            </tr>
                        </form>
                        <?php
                        if (Session::has('trangthai')) {
                            if (Session::has('trangthai') == 1)
                                echo "<script>alert('Sửa Đề Tài Thành Công!')</script>";
                            else {
                                echo "<script>alert('Sửa Đề Tài Thất Bại!')</script>";
                            }
                        }
                        ?>
                    </table>
                </td>
            </tr>                        
            <?php
        }
    }
    ?>
</table>

@include('canbo.themdetai')
<script type='text/javascript'>
    function OpenPop(idmask, idfrm)
    {
        document.getElementById(idmask).style.display = 'block';
        document.getElementById(idfrm).style.display = 'block';
    }
    function ClosePop(idmask, idfrm)
    {
        document.getElementById(idmask).style.display = 'none';
        document.getElementById(idfrm).style.display = 'none';
    }
</script>
@stop

